//
//  HomeAdDetailViewController.m
//  51易借
//
//  Created by apple on 2017/9/15.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "HomeAdDetailViewController.h"
@interface HomeAdDetailViewController ()<UIWebViewDelegate>
@property (nonatomic,strong)UIWebView * web;
@property (nonatomic,strong)UIView * topView;
@property (nonatomic,strong)HomeDetailModel * detailModel;
@end

@implementation HomeAdDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;

    [self setupNavBar];
    [self setupUI];
    [self updateUI];
    [self getDetailModel];
    // Do any additional setup after loading the view.
}



-(void)updateUI
{
    self.title = self.model.name;
    self.automaticallyAdjustsScrollViewInsets = NO;
        self.web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 64 * SCREENH6, SCREEN_WIDTH, SCREENH_HEIGHT-64 * SCREENH6)];
        self.web.scalesPageToFit = YES;
    self.web.delegate = self;
        [self.view addSubview:self.web];
}

- (void)webViewDidFinishLoad:(UIWebView*)webView {
    
    
    [self.web stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '200%'"];
    
}

- (void)setupNavBar{
    
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)setupUI{
    
    //    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = ColorWithRGB(0xff7907);
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    //
    
}


- (void)viewDidLayoutSubviews{
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(64 * SCREENH6);
    }];
}


-(void)getDetailModel
{
    ParaModel*para = [ParaModel new];
    para.announceId = self.model.id;
    
    [[NetworkTool shareManager] POST:[Interfacefile getAnnounceDetail] Param:[para toDictionary] andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        
//        NSLog(@"web%@",responseObject);
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            self.detailModel = [[HomeDetailModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            
            [self.web loadHTMLString:self.detailModel.contentHtml baseURL:nil];
        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
}





@end
